using Domain.Dto;
using Gmmy.DomainExtension;
using Gmmy.Utility;
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace Domain.Model
{
    /// <summary>
    /// 角色表模型
    /// </summary>
    public class Role : EntityBase
    {
		#region 领域对象属性
        /// <summary>
        /// 主键
        /// </summary>
        [DisplayName(@"主键")]
        [Key]
        public Guid ID { get; set; }

        /// <summary>
        /// 角色名称
        /// </summary>
        [DisplayName(@"角色名称")]
        public string RoleName { get; set; }

        /// <summary>
        /// 角色描述
        /// </summary>
        [DisplayName(@"角色描述")]
        public string Remark { get; set; }

        /// <summary>
        /// 排序
        /// </summary>
        [DisplayName(@"排序")]
        public int Sort { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        [DisplayName(@"创建时间")]
        public DateTime CreateTime { get; set; }

        /// <summary>
        /// 逻辑删除
        /// </summary>
        [DisplayName(@"逻辑删除")]
        public bool IsDeleted { get; set; }


        #endregion

		#region 领域对象行为
		public Role() { }//空构造函数

		/// <summary>
        /// 创建角色表
        /// </summary>
        /// <param name="input"></param>
        public Role(RoleCreateInput input)
        {
            if (string.IsNullOrWhiteSpace(input.RoleName))
            {
                throw new CustomException("角色名必须存在!");
            }
            if (input.Sort<0)
            {
                throw new CustomException("排序不能小于0!");
            }
            ID = Guid.NewGuid();
            RoleName = input.RoleName;
            Remark = input.Remark;
            Sort = input.Sort;

            CreateTime = DateTime.Now;
            IsDeleted = false;
        }
        /// <summary>
        /// 更新角色表
        /// </summary>
        /// <param name="input"></param>
        public void Update(RoleUpdateInput input)
        {
            if (string.IsNullOrWhiteSpace(input.RoleName))
            {
                throw new CustomException("角色名必须存在!");
            }
            if (input.Sort < 0)
            {
                throw new CustomException("排序不能小于0!");
            }
            RoleName = input.RoleName;
            Remark = input.Remark;
            Sort = input.Sort;
        }

        #endregion

    }
}